home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / MovieMeter (NL).ifs < prev    next >
Text File  |  2005-05-14  |  5KB  |  184 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Antoine Potten
  8. Title=MovieMeter.nl
  9. Description=MovieMeter.nl import script
  10. Site=www.moviemeter.nl
  11. Language=NL
  12. Version=2.1
  13. Requires=3.5.0
  14. Comments=Previous version made by JanC and corrections by <link>rolandb5@hotmail.com</link>|Rewritten by Antoine Potten after a site change (v 2.0)
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19. AllCountries=0|0|0=Take only first country|1=Take all countries (separated by "/")
  20.  
  21. ***************************************************)
  22.  
  23. program MovieMeter;
  24.  
  25. uses
  26.   StringUtils1;
  27.  
  28. var
  29.   MovieName: string;
  30.  
  31. procedure AnalyzeMoviePage(Address: string);
  32. var
  33.   PageText, Line, Value: string;
  34. begin
  35.   PageText := GetPage(Address);
  36.  
  37.   // URL
  38.   SetField(fieldURL, Address);
  39.  
  40.   // title & year
  41.   Line := TextBetween(PageText, '<h1>', '</h1>');
  42.   Value := TextBetween(Line, '(', ')');
  43.   SetField(fieldYear, Value);
  44.   Value := Trim(TextBefore(Line, '(', ''));
  45.   HTMLDecode(Value);
  46.   SetField(fieldOriginalTitle, Value);
  47.   
  48.   // translated title
  49.   Line := TextBetween(PageText, '<p>Alternatieve titel: ', '<br />');
  50.   if Line <> '' then
  51.   begin
  52.     HTMLDecode(Line);
  53.     SetField(fieldTranslatedTitle, Line);
  54.   end;
  55.   
  56.   Value := TextBetween(PageText, '<div id="film_info" style="height: 465px">', '<br />');
  57.   if Value = '' then
  58.     Value := TextBetween(PageText, '<div id="film_info" style="height: 490px">', '<br />');
  59.   Line := RemainingText;
  60.  
  61.   // Country
  62.   if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0)  then
  63.     Value := TextBefore(Value, ' / ', '');
  64.   HTMLDecode(Value);
  65.   SetField(fieldCountry, Value);
  66.  
  67.   // Category
  68.   Value := TextBefore(Line, '<br />', '');
  69.   Line := RemainingText;
  70.   HTMLDecode(Value);
  71.   SetField(fieldCategory, Value);
  72.   
  73.   // Length
  74.   Value := TextBefore(Line, ' minuten<br />', '');
  75.   Line := RemainingText;
  76.   HTMLDecode(Value);
  77.   SetField(fieldLength, Value);
  78.   
  79.   // Director
  80.   Value := TextBetween(Line, 'geregisseerd door ', '<br />');
  81.   Line := RemainingText;
  82.   HTMLRemoveTags(Value);
  83.   HTMLDecode(Value);
  84.   SetField(fieldDirector, Value);
  85.   
  86.   // Actors
  87.   Value := TextBetween(Line, 'met ', '<br />');
  88.   Line := RemainingText;
  89.   HTMLDecode(Value);
  90.   SetField(fieldActors, Value);
  91.   
  92.   // Description
  93.   Value := TextBetween(Line, '<br />', '</div>');
  94.   HTMLRemoveTags(Value);
  95.   HTMLDecode(Value);
  96.   SetField(fieldDescription, Value);
  97.   
  98.   // Picture
  99.   Value := TextBetween(Line, '<img class="poster" src="', '" ');
  100.   if Value <> '' then
  101.   begin
  102.     GetPicture(Value);
  103.   end;
  104.   
  105.   // Rating
  106.   Value := TextBetween(Line, '<br />gemiddelde: ', '</div>');
  107.   Value := StringReplace(FloatToStr(StrToFloat(StringReplace(Value, ',', '.')) * 2), ',', '.');
  108.   SetField(fieldRating, Value);
  109.   
  110. end;
  111.  
  112.  
  113. procedure AnalyzeResultsPage(Address: string);
  114. var
  115.   Page: TStringList;
  116.   Line: string;
  117.   MovieAddress: string;
  118.   MovieTitle: string;
  119. begin
  120.   // get results page
  121.   Page := TStringList.Create;
  122.   Page.Text := GetPage(Address);
  123.  
  124.   // get redirect javascript
  125.   Line := Page.GetString(Page.Count-1);
  126.  
  127.   // more than 1 movie found
  128.   if Pos('location.href = "http://www.moviemeter.nl/film/searchresults', Line) <> 0 then
  129.   begin
  130.     PickTreeClear;
  131.     PickTreeAdd('Zoekresultaten voor ' + MovieName, '');
  132.  
  133.     // get results page
  134.     Page.Text := GetPage('http://www.moviemeter.nl/film/searchresults');
  135.  
  136.     Line := TextBetween(Page.Text, '<div class="filmresults_row1">', '<p>Pas je zoekopdracht aan:</p>');
  137.     while Pos('filmresults_row', Line) > 0 do
  138.     begin
  139.       MovieAddress := TextBetween(Line, 'href="', '" >');
  140.       MovieTitle := TextBefore(Line, '</p></div>', '');
  141.       Line := RemainingText;
  142.       HTMLRemoveTags(MovieTitle);
  143.       HTMLDecode(MovieTitle);
  144.       PickTreeAdd(Trim(MovieTitle), MovieAddress);
  145.     end;
  146.  
  147.     // if user picks a movie from the results list, import movie details
  148.     if PickTreeExec(Address) then
  149.       AnalyzeMoviePage(Address);
  150.   end
  151.   else
  152.   begin
  153.     MovieAddress := TextBetween(Line, '"', '";');
  154.     if MovieAddress <> 'http://www.moviemeter.nl/film/' then
  155.       // if only 1 movie found --> redirect to movie page
  156.       AnalyzeMoviePage(MovieAddress)
  157.     else
  158.       // no movies found
  159.       ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  160.   end;
  161.   Page.Free;
  162. end;
  163.  
  164.  
  165. begin
  166.   if CheckVersion(3,5,0) then
  167.   begin
  168.     if StringUtils1_Version >= 2 then
  169.     begin
  170.       MovieName := GetField(fieldOriginalTitle);
  171.       if MovieName = '' then
  172.         MovieName := GetField(fieldTranslatedTitle);
  173.       if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then
  174.       begin
  175.         AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName));
  176.       end;
  177.     end
  178.     else
  179.       ShowMessage('The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)');
  180.   end
  181.   else
  182.     ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)');
  183. end.
  184.